Skip to content

fix(last_insert_rowid): publish rowid from cached_write + fall back to real SQLite when pg_conn lookup misses#13

Draft
JorisM wants to merge 2 commits into
cgnl:mainfrom
JorisM:fix/last-insert-rowid
Draft

fix(last_insert_rowid): publish rowid from cached_write + fall back to real SQLite when pg_conn lookup misses#13
JorisM wants to merge 2 commits into
cgnl:mainfrom
JorisM:fix/last-insert-rowid

Conversation

@JorisM

@JorisM JorisM commented May 22, 2026

Copy link
Copy Markdown
Contributor

Draft pending live pilot verification. Stacks on #2 (rewrite-plain-INSERT). Surfaces only after #2 is in.

Two related issues:

  • Bug #3a: cached_write never published row id → Plex's sqlite3_last_insert_rowid → 0 → SOCI threw DB::Exception.
  • Bug #3b: last_insert_rowid_impl returned 0 when registry lookup missed AND global was 0; added orig_sqlite3_last_insert_rowid fallback.

Detailed write-up: docs/debug/plex-pg-db-exception-bug-report.md.

JorisM added 2 commits May 22, 2026 18:00
…LICT DO UPDATE

Plain INSERT into shim-added UNIQUE-keyed tables (statistics_bandwidth,
statistics_media, metadata_item_settings) raises unique_violation on PG;
PMS does not catch and aborts with DB::Exception. Extend transform_insert
to emit ON CONFLICT DO UPDATE for plain INSERTs whose target table has
known conflict columns. DO UPDATE (not DO NOTHING) is intentional so the
trailing RETURNING id clause in cached_write still returns the row id.

Verified via cargo run --example crash_repro and live pilot pod.
…o real SQLite when pg_conn lookup misses

Bug #3a: Cached INSERT … RETURNING id never published the row id to
Plex's sqlite3_last_insert_rowid view. cached_write now mirrors the
non-cached write path: writes ec.last_insert_rowid and calls
rust_set_global_last_insert_rowid after a successful exec.

Bug #3b: last_insert_rowid_impl returned 0 when the registry lookup
missed AND the global was 0 — never fell back to the real shadow
SQLite. Added orig_sqlite3_last_insert_rowid(db) fallback so the
shadow's view is the source of truth in that path. Required import
added in db_interpose_metadata.rs.

Verified live: EXCEPTION counter stays at 0 across the 5s stats
roll-up cycle; `real_sqlite=N` log markers + `global=N` ticking
with N>0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant